//
//  MatteMaterial.hpp
//  RayTracer
//
//  Created by 俞云康 on 3/25/16.
//  Copyright © 2016 yushroom. All rights reserved.
//

#ifndef MatteMaterial_hpp
#define MatteMaterial_hpp

#include "Material.hpp"
#include "Params.hpp"
#include "Lambertian.hpp"
#include "OrenNayar.hpp"

class MatteMaterial : public Material {
private:
    std::shared_ptr<Texture> Kd;
    //Lambertian lambert_brdf;
    
public:
    MatteMaterial(std::shared_ptr<Texture> Kd) : Kd(Kd) { }
    
    //    virtual Color diffuse(const HitInfo& hit) const override {
    //        return Kd->sample(hit.texcoord.x, hit.texcoord.y);
    //    }
    
    static shared_ptr<Material> create(const Params& params) {
        std::shared_ptr<Texture> Kd = Texture::create(params.child("texture"));
        return  make_shared<MatteMaterial>(Kd);
    }
    
//    virtual std::shared_ptr<BxDF> get_brdf(const HitInfo& hit) const override {
//        return std::make_shared<Lambertian>(&hit, Kd->sample(hit.texcoord));
//    }
    
    virtual shared_ptr<BSDF> getBSDF(const HitInfo& hit) const override {
        auto bsdf = make_shared<BSDF>(hit, hit.normal);
        bsdf->add(new Lambertian(&hit, Kd->sample(hit.texcoord)));
        //bsdf->add(new OrenNayar(&hit, Kd->sample(hit.texcoord), 1.0f));
        return bsdf;
    }
};


#endif /* MatteMaterial_hpp */
